#include "expedition.h"

Expedition::Expedition(City city, QObject *parent) : AbstractDeck(parent)
{
  m_city = city;
}

bool Expedition::isCardAccepted(int card) const {
    bool cardAllowed;
    int topCard;
    int cardValue;
    int maxValue;
    City city = getCity(card);
    if (city != m_city) {
        cardAllowed = false;
    }
    else
    {
        if (m_cards.isEmpty())
        {
            cardAllowed = true;
        }
        else 
        {
            topCard = m_cards.last();
            if (isMultiplier(topCard)) 
            {
                cardAllowed = true;
            }
            else
            {
                maxValue = getValue(topCard);
                if (maxValue > cardValue) 
                {
                    cardAllowed = true;
                }
                else
                {
                    cardAllowed = false;
                }
            }
        }
    }
    
    return cardAllowed;
}

bool Expedition::addCard(int Card)
{
    bool operationAllowed;
    if (!isCardAccepted(Card))
    {
        operationAllowed = false;
    }
    else
    {
        m_cards.append(Card);
        operationAllowed =true;
    }
    return operationAllowed;
}
